<%-- 
    Document   : home
    Created on : Sep 3, 2013, 11:26:10 PM
    Author     : Thai Ha Cong
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="description" content="<s:property value="category.description"/>">
        <title><s:property value="category.name"/> - Online Shopping System</title>
        <link href="<%= request.getContextPath()%>/css/style.css" rel="stylesheet" type="text/css"/>
    </head>
    <body>
        <div class="headerbg">
            <%@include file="include/iHeader.jsp" %>
        </div>
        <div class="contentbg">
            <div class="content1">
                <div class="content2">
                    <div class="contentLeft">
                        <div class="categories">
                            <div class="allCat">ALL CATEGORIES</div>
                            <%@include file="/include/iCategories.jsp" %>
                        </div>
                    </div>
                    <div class="contentRight">
                        <div class="body">
                            <div class="breadcrumb">
                                <s:url action="home" var="homeUrl"></s:url>

                                <s:a href="%{homeUrl}" title="Home" theme="simple">Home</s:a>
                                    >>
                                <s:property value="category.name"/>
                            </div>
                            <div class="bodyUpper">
                                <s:iterator value="productsResultList">
                                    <div class="pSummary">
                                        <div class="pSmallImage">
                                            <a href="<%= request.getContextPath()%>/product/<s:property value='idProduct'/>/<s:property value='name.replaceAll(" ", "-")'/>" title="<s:property value='name + "\r\n" + summary'/>">
                                                <img src="<%= request.getContextPath()%>/<s:property value='imageurl'/>" alt="<s:property value='name'/>" title="<s:property value='name + "\r\n" + summary'/>" width="200" height="auto" />
                                            </a>
                                        </div>
                                        <div class="pSummmaryInfo">
                                            <div class="pName">
                                                <s:property value="name"/>
                                            </div>
                                            <div class="pPrice-was">
                                                $<s:property value="getText('{0,number,#,##0.00}',{unitPrice})"/>
                                            </div>
                                            <div class="pPrice-current">
                                                $<s:property value="getText('{0,number,#,##0.00}',{unitPrice-sale})"/>
                                            </div>
                                            <div class="pAddButton">
                                                <s:if test="%{stockQuantity==0}">
                                                    <img src="<%= request.getContextPath()%>/css/cannotAddToCart.png" title="Currently Out of Stock" alt="Out of Stock" width="25" height="25"/>
                                                </s:if>
                                                <s:else>
                                                    <s:form action="addToCart" method="POST">
                                                        <s:hidden name="productId" value="%{idProduct}"></s:hidden>
                                                        <s:hidden name="productQuantity" value="1"></s:hidden>
                                                        <s:set var="contextPath"><%= request.getContextPath()%></s:set>
                                                        <s:submit type="image" src="%{contextPath}/css/addToCart.png" cssStyle="width: 25px; height: 25px" title="Add this to Cart" theme="simple"/>
                                                    </s:form>
                                                </s:else>
                                            </div>
                                        </div>
                                    </div>
                                </s:iterator>
                            </div>
                            <div class="pageNavigation">
                                <div class="pageInfo">
                                    Page <s:property value="currentPage"/> of <s:property value="totalPage"/>
                                </div>
                                <div class="pageNumberDisplay">
                                    <s:if test="%{totalPage == 0}">    
                                        There's nothing!
                                    </s:if>
                                    <s:else>
                                        <!--First Previous-->
                                        <s:if test="%{currentPage > 1}">
                                            <s:form action="category/%{idCategory}/%{cname}" method="POST" cssStyle="display: inline;">
                                                <s:hidden name="currentPage" value="1"/>
                                                <s:submit value="First" cssStyle="width: 52px"/>                                   
                                            </s:form>
                                            <s:form action="category/%{idCategory}/%{cname}" method="POST" cssStyle="display: inline;">
                                                <s:hidden name="currentPage" value="%{currentPage - 1}"/>
                                                <s:submit value="Previous" cssStyle="width: 80px"/>                                   
                                            </s:form>
                                        </s:if>
                                        <s:else>
                                            <!--Disable button-->
                                            <s:form cssStyle="display: inline;">
                                                <s:submit value="First" cssStyle="width: 52px; display: inline;" disabled="true"/>
                                            </s:form>
                                            <s:form cssStyle="display: inline;">
                                                <s:submit value="Previous" cssStyle="width: 80px; display: inline;" disabled="true"/>
                                            </s:form>
                                        </s:else>
                                        <!--Page Number-->
                                        <s:if test="%{totalPage <= 5}">
                                            <s:iterator begin="1" end="totalPage" step="1" status="iStatus">
                                                <s:if test="%{(#iStatus.index + 1) == currentPage}">
                                                    <s:form cssStyle="display: inline;">
                                                        <s:submit value="%{currentPage}" cssStyle="width: 44px; display: inline;" disabled="true"/>
                                                    </s:form>
                                                </s:if>
                                                <s:else>
                                                    <s:form action="category/%{idCategory}/%{cname}" method="POST" cssStyle="display: inline;">
                                                        <s:hidden name="currentPage" value="%{#iStatus.index + 1}"/>
                                                        <s:submit value="%{#iStatus.index + 1}" cssStyle="width: 44px; display: inline;"/>                                   
                                                    </s:form>
                                                </s:else>
                                            </s:iterator>
                                        </s:if>
                                        <s:elseif test="%{currentPage < 3}">
                                            <!--Total Page > 5-->
                                            <!--2 first pages-->
                                            <s:iterator begin="1" end="5" step="1" status="iStatus">
                                                <s:if test="%{#iStatus.index + 1 == currentPage}">
                                                    <s:form cssStyle="display: inline">
                                                        <s:submit value="%{currentPage}" cssStyle="width: 44px; display: inline;" disabled="true"/>
                                                    </s:form>
                                                </s:if>
                                                <s:else>
                                                    <s:form action="category/%{idCategory}/%{cname}" method="POST" cssStyle="display: inline;">
                                                        <s:hidden name="currentPage" value="%{#iStatus.index + 1}"/>
                                                        <s:submit value="%{#iStatus.index + 1}" cssStyle="width: 44px; display: inline;"/>
                                                    </s:form>
                                                </s:else>
                                            </s:iterator>
                                        </s:elseif>
                                        <s:elseif test="%{currentPage > totalPage - 2}">
                                            <!--Total Page > 5-->
                                            <!--2 last pages-->
                                            <s:iterator begin="1" end="5" step="1" status="iStatus">
                                                <s:if test="%{#iStatus.index + 1 + totalPage - 5 == currentPage}">
                                                    <s:form cssStyle="display: inline">
                                                        <s:submit value="%{currentPage}" cssStyle="width: 44px; display: inline;" disabled="true"/>
                                                    </s:form>
                                                </s:if>
                                                <s:else>
                                                    <s:form action="category/%{idCategory}/%{cname}" method="POST" cssStyle="display: inline;">
                                                        <s:hidden name="currentPage" value="%{#iStatus.index + 1 + totalPage - 5}"/>
                                                        <s:submit value="%{#iStatus.index + 1 + totalPage - 5}" cssStyle="width: 44px; display: inline;"/>                                   
                                                    </s:form>
                                                </s:else>
                                            </s:iterator>
                                        </s:elseif>
                                        <s:else>
                                            <!--Total Page > 5-->
                                            <!--current page >=3 , <= total page -2 -->
                                            <s:iterator begin="1" end="5" step="1" status="iStatus">
                                                <s:if test="%{#iStatus.index + 1 + currentPage - 3 == currentPage}">
                                                    <s:form cssStyle="display: inline">
                                                        <s:submit value="%{currentPage}" cssStyle="width: 44px; display: inline;" disabled="true"/>
                                                    </s:form>
                                                </s:if>
                                                <s:else>
                                                    <s:form action="category/%{idCategory}/%{cname}" method="POST" cssStyle="display: inline;">
                                                        <s:hidden name="currentPage" value="%{#iStatus.index + 1+ currentPage - 3}"/>
                                                        <s:submit value="%{#iStatus.index + 1 + currentPage - 3}" cssStyle="width: 44px; display: inline;"/>                                   
                                                    </s:form>
                                                </s:else>
                                            </s:iterator>
                                        </s:else>
                                        <!--Next Last-->
                                        <s:if test="%{currentPage < totalPage}">
                                            <s:form action="category/%{idCategory}/%{cname}" method="POST" cssStyle="display: inline;">
                                                <s:hidden name="currentPage" value="%{currentPage + 1}"/>
                                                <s:submit value="Next" cssStyle="width: 80px"/>
                                            </s:form>
                                            <s:form action="category/%{idCategory}/%{cname}" method="POST" cssStyle="display: inline;">
                                                <s:hidden name="currentPage" value="%{totalPage}"/>
                                                <s:submit value="Last" cssStyle="width: 52px"/>
                                            </s:form>
                                        </s:if>
                                        <s:else>
                                            <s:form cssStyle="display: inline">
                                                <s:submit value="Next" cssStyle="width: 80px; display: inline;" disabled="true"/>
                                            </s:form>
                                            <s:form cssStyle="display: inline">
                                                <s:submit value="Last" cssStyle="width: 52px; display: inline;" disabled="true"/>
                                            </s:form>
                                        </s:else>
                                    </s:else>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="footerbg">
            <%@include file="/include/iFooter.jsp" %>
        </div>
    </body>
</html>